﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web;
using System.Web.SessionState;
namespace jnxc.Web.addprevention
{
    /// <summary>
    /// GetADD 的摘要说明
    /// </summary>
    public class GetADD : IHttpHandler, IRequiresSessionState
    {
        jnxc.BLL.addprevention bll = new jnxc.BLL.addprevention();
        StringBuilder result = new StringBuilder();
        
        StringBuilder sb = new StringBuilder();
        public void ProcessRequest(HttpContext context)
        {

            string ac = "";
            if (null != context.Request.Form["action"])
            {//获取前台传来的值  
                ac = context.Request.Form["action"].ToString().Trim();
            }
            else if (null != context.Request.QueryString["action"])
            {
                ac = context.Request.QueryString["action"].ToString().Trim();
            }

            if (ac == "query")
                Query(context);
            else if (ac == "add")
                add(context);            
            else if (ac == "modify")
                modify(context);           
            else if (ac == "delete")
                delete(context);
            else if (ac == "querymy")
                Querymy(context);
            else if (ac == "queryt")
                Queryt(context);   //取得虫地区的树，树为下级区域
        }
       
        public void delete(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int uid = 0;
            string uidstr = context.Request.QueryString["apid"];
            if (uidstr != "")
                uid = int.Parse(uidstr);            
            if (bll.Delete(uid))
            {
                context.Response.Write("T");//返回给前台页面  
                context.Response.End();

            }
            else
            {
                context.Response.Write("F");//返回给前台页面  
                context.Response.End();

            }

        }
       
        public void modify(HttpContext context)
        {
            if (Web.Admin.myinfo.isLogin(context))
            {
                context.Response.ContentType = "text/plain";
                DateTime? fztime = null, dctime = null;
                int aid = 0, dpid = 0, generation = 0, sszs = 0;
                decimal shouldarea = 0, jzarea = 0, jcarea = 0, dckdgarea = 0, fbarea = 0, sdlj = 0, ljqd = 0, ljzd = 0, ljzzd = 0, fssum = 0, fsqd = 0, fszd = 0, fszzd = 0, tbcnew = 0, yjzh = 0, fsrate = 0, workarea = 0,
                    wghwork = 0, zja = 0, xja = 0, bda = 0, fla = 0, qttda = 0, zwyyja = 0, qtsfa = 0, fsfza = 0, wghhfa = 0, wlfza = 0, rgfza = 0, qtfza = 0, qtwgha = 0, hxfza = 0, fzsum = 0, yfarea = 0, ffarea = 0, zjb = 0, xjb = 0,
                    bdb = 0, flb = 0, qttdb = 0, qtsfb = 0, fsb = 0, rgb = 0, qtfzb = 0, hfb = 0, tbcxfz = 0, wghfzrate = 0, fzrate = 0, czarea = 0, whzharea = 0, czrate = 0, fzfy = 0, zjl = 0, xjl = 0, bdl = 0, tdkc = 0, fsyl = 0, yjll = 0,
                    jzll = 0, yjl = 0, hxqt = 0;
                string temp = "";
                string ap = context.Request.Form["apid"];
                int apid = 0;
                if (ap != "") apid = int.Parse(ap);
                temp = context.Request.Form["aid"];
                if (temp != "") aid = int.Parse(temp);
                string trees = context.Request.Form["trees"];

                temp = context.Request.Form["shouldarea"];
                if (temp != "") shouldarea = decimal.Parse(temp);
                temp = context.Request.Form["dpid"];
                if (temp != "") dpid = int.Parse(temp);
                temp = context.Request.Form["jzarea"];
                if (temp != "") jzarea = decimal.Parse(temp);
                temp = context.Request.Form["jcarea"];
                if (temp != "") jcarea = decimal.Parse(temp);
                temp = context.Request.Form["generation"];
                if (temp != "") generation = int.Parse(temp);
                temp = context.Request.Form["dctime"];
                if (temp != "") dctime = DateTime.Parse(temp);
                temp = context.Request.Form["dckdgarea"];
                if (temp != "") dckdgarea = decimal.Parse(temp);
                temp = context.Request.Form["fbarea"];
                if (temp != "") fbarea = decimal.Parse(temp);
                temp = context.Request.Form["sdlj"];
                if (temp != "") sdlj = decimal.Parse(temp);
                temp = context.Request.Form["ljzd"];
                if (temp != "") ljzd = decimal.Parse(temp);
                temp = context.Request.Form["ljzzd"];
                if (temp != "") ljzzd = decimal.Parse(temp);
                temp = context.Request.Form["fssum"];
                if (temp != "") fssum = decimal.Parse(temp);
                temp = context.Request.Form["fsqd"];
                if (temp != "") fsqd = decimal.Parse(temp);
                temp = context.Request.Form["fszd"];
                if (temp != "") fszd = decimal.Parse(temp);
                temp = context.Request.Form["fszzd"];
                if (temp != "") fszzd = decimal.Parse(temp);
                temp = context.Request.Form["tbcnew"];
                if (temp != "") tbcnew = decimal.Parse(temp);
                temp = context.Request.Form["yjzh"];
                if (temp != "") yjzh = decimal.Parse(temp);
                temp = context.Request.Form["fsrate"];
                if (temp != "") fsrate = decimal.Parse(temp);
                temp = context.Request.Form["fztime"];
                if (temp != "") fztime = DateTime.Parse(temp);
                temp = context.Request.Form["workarea"];
                if (temp != "") workarea = decimal.Parse(temp);
                temp = context.Request.Form["wghwork"];
                if (temp != "") wghwork = decimal.Parse(temp);
                temp = context.Request.Form["zja"];
                if (temp != "") zja = decimal.Parse(temp);
                temp = context.Request.Form["xja"];
                if (temp != "") xja = decimal.Parse(temp);
                temp = context.Request.Form["bda"];
                if (temp != "") bda = decimal.Parse(temp);
                temp = context.Request.Form["fla"];
                if (temp != "") fla = decimal.Parse(temp);
                temp = context.Request.Form["qttda"];
                if (temp != "") qttda = decimal.Parse(temp);
                temp = context.Request.Form["zwyyja"];
                if (temp != "") zwyyja = decimal.Parse(temp);
                temp = context.Request.Form["qtsfa"];
                if (temp != "") qtsfa = decimal.Parse(temp);
                temp = context.Request.Form["fsfza"];
                if (temp != "") fsfza = decimal.Parse(temp);
                temp = context.Request.Form["wghhfa"];
                if (temp != "") wghhfa = decimal.Parse(temp);
                temp = context.Request.Form["wlfza"];
                if (temp != "") wlfza = decimal.Parse(temp);
                temp = context.Request.Form["rgfza"];
                if (temp != "") rgfza = decimal.Parse(temp);
                temp = context.Request.Form["qtfza"];
                if (temp != "") qtfza = decimal.Parse(temp);
                temp = context.Request.Form["qtwgha"];
                if (temp != "") qtwgha = decimal.Parse(temp);
                temp = context.Request.Form["hxfza"];
                if (temp != "") hxfza = decimal.Parse(temp);
                temp = context.Request.Form["fzsum"];
                if (temp != "") fzsum = decimal.Parse(temp);
                temp = context.Request.Form["yfarea"];
                if (temp != "") yfarea = decimal.Parse(temp);
                temp = context.Request.Form["ffarea"];
                if (temp != "") ffarea = decimal.Parse(temp);
                temp = context.Request.Form["zjb"];
                if (temp != "") zjb = decimal.Parse(temp);
                temp = context.Request.Form["xjb"];
                if (temp != "") xjb = decimal.Parse(temp);
                temp = context.Request.Form["bdb"];
                if (temp != "") bdb = decimal.Parse(temp);
                temp = context.Request.Form["flb"];
                if (temp != "") flb = decimal.Parse(temp);
                temp = context.Request.Form["qttdb"];
                if (temp != "") qttdb = decimal.Parse(temp);
                temp = context.Request.Form["qtsfb"];
                if (temp != "") qtsfb = decimal.Parse(temp);
                temp = context.Request.Form["fsb"];
                if (temp != "") fsb = decimal.Parse(temp);
                temp = context.Request.Form["rgb"];
                if (temp != "") rgb = decimal.Parse(temp);
                temp = context.Request.Form["qtfzb"];
                if (temp != "") qtfzb = decimal.Parse(temp);
                temp = context.Request.Form["hfb"];
                if (temp != "") hfb = decimal.Parse(temp);
                temp = context.Request.Form["tbcxfz"];
                if (temp != "") tbcxfz = decimal.Parse(temp);
                temp = context.Request.Form["wghfzrate"];
                if (temp != "") wghfzrate = decimal.Parse(temp);
                temp = context.Request.Form["fzrate"];
                if (temp != "") fzrate = decimal.Parse(temp);
                temp = context.Request.Form["czarea"];
                if (temp != "") czarea = decimal.Parse(temp);
                temp = context.Request.Form["whzharea"];
                if (temp != "") whzharea = decimal.Parse(temp);
                temp = context.Request.Form["czrate"];
                if (temp != "") czrate = decimal.Parse(temp);
                temp = context.Request.Form["whzharea"];
                if (temp != "") whzharea = decimal.Parse(temp);
                temp = context.Request.Form["czrate"];
                if (temp != "") whzharea = decimal.Parse(temp);
                temp = context.Request.Form["fzfy"];
                if (temp != "") fzfy = decimal.Parse(temp);
                temp = context.Request.Form["sszs"];
                if (temp != "") sszs = int.Parse(temp);
                temp = context.Request.Form["zjl"];
                if (temp != "") zjl = decimal.Parse(temp);

                temp = context.Request.Form["xjl"];
                if (temp != "") xjl = decimal.Parse(temp);
                temp = context.Request.Form["bdl"];
                if (temp != "") bdl = decimal.Parse(temp);
                temp = context.Request.Form["tdkc"];
                if (temp != "") tdkc = decimal.Parse(temp);
                temp = context.Request.Form["fsyl"];
                if (temp != "") fsyl = decimal.Parse(temp);
                temp = context.Request.Form["yjll"];
                if (temp != "") yjll = decimal.Parse(temp);
                temp = context.Request.Form["jzll"];
                if (temp != "") jzll = decimal.Parse(temp);
                temp = context.Request.Form["yjl"];
                if (temp != "") yjl = decimal.Parse(temp);
                temp = context.Request.Form["hxqt"];
                if (temp != "") hxqt = decimal.Parse(temp);

                jnxc.Model.addprevention model = new jnxc.Model.addprevention();
                model.apid = apid;
                model.aid = aid;
                model.dpid = dpid;
                model.trees = trees;
                model.shouldarea = shouldarea;
                model.jzarea = jzarea;
                model.jcarea = jcarea;
                model.generation = generation;
                model.dctime = dctime;
                model.dckdgarea = dckdgarea;
                model.fbarea = fbarea;
                model.sdlj = sdlj;
                model.ljqd = ljqd;
                model.ljzd = ljzd;
                model.ljzzd = ljzzd;
                model.fssum = fssum;
                model.fsqd = fsqd;
                model.fszd = fszd;
                model.fszzd = fszzd;
                model.tbcnew = tbcnew;
                model.yjzh = yjzh;
                model.fsrate = fsrate;
                model.fztime = fztime;
                model.workarea = workarea;
                model.wghwork = wghwork;
                model.zja = zja;
                model.xja = xja;
                model.bda = bda;
                model.fla = fla;
                model.qttda = qttda;
                model.zwyyja = zwyyja;
                model.qtsfa = qtsfa;
                model.fsfza = fsfza;
                model.wghhfa = wghhfa;
                model.wlfza = wlfza;
                model.rgfza = rgfza;
                model.qtfza = qtfza;
                model.qtwgha = qtwgha;
                model.hxfza = hxfza;
                model.fzsum = fzsum;
                model.yfarea = yfarea;
                model.ffarea = ffarea;
                model.zjb = zjb;
                model.xjb = xjb;
                model.bdb = bdb;
                model.flb = flb;
                model.qttdb = qttdb;
                model.qtsfb = qtsfb;
                model.rgb = rgb;
                model.qtfzb = qtfzb;
                model.hfb = hfb;
                model.tbcxfz = tbcxfz;
                model.wghfzrate = wghfzrate;
                model.fzrate = fzrate;
                model.czarea = czarea;
                model.whzharea = whzharea;
                model.czrate = czrate;
                model.fzfy = fzfy;
                model.sszs = sszs;
                model.zjl = zjl;
                model.xjl = xjl;
                model.bdl = bdl;
                model.tdkc = tdkc;
                model.fsyl = fsyl;
                model.yjll = yjll;
                model.jzll = jzll;
                model.yjl = yjl;
                model.hxqt = hxqt;
                model.fsb = fsb;
                model.uid = Web.Admin.myinfo.getID(context);                
                if (bll.Update(model))
                {
                    context.Response.Write("T");//返回给前台页面  
                    context.Response.End();
                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();
                }
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();
            }

        }
       
        public void add(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            {	
                DateTime? fztime=null,dctime=null;
                int aid=0,dpid=0,generation=0,sszs=0;
                decimal shouldarea=0,jzarea=0,jcarea=0,dckdgarea=0,fbarea=0,sdlj=0,ljqd=0,ljzd=0,ljzzd=0,fssum=0,fsqd=0,fszd=0,fszzd=0,tbcnew=0,yjzh=0,fsrate=0,workarea=0,
                    wghwork=0,zja=0,xja=0,bda=0,fla=0,qttda=0,zwyyja=0,qtsfa=0,fsfza=0,wghhfa=0,wlfza=0,rgfza=0,qtfza=0,qtwgha=0,hxfza=0,fzsum=0,yfarea=0,ffarea=0,zjb=0,xjb=0,
                    bdb=0,flb=0,qttdb=0,qtsfb=0,fsb=0,rgb=0,qtfzb=0,hfb=0,tbcxfz=0,wghfzrate=0,fzrate=0,czarea=0,whzharea=0,czrate=0,fzfy=0,zjl=0,xjl=0,bdl=0,tdkc=0,fsyl=0,yjll=0,
                    jzll=0,yjl=0,hxqt=0;
                string temp = "";
                 temp = context.Request.Form["aid"];
                 if (temp != "") aid = int.Parse(temp);
                 string trees = context.Request.Form["trees"];

                  temp = context.Request.Form["shouldarea"];
                  if (temp != "") shouldarea = decimal.Parse(temp);
                   temp = context.Request.Form["dpid"];
                   if (temp != "") dpid = int.Parse(temp);
                  temp = context.Request.Form["jzarea"];
                  if (temp != "") jzarea = decimal.Parse(temp);
                  temp = context.Request.Form["jcarea"];
                  if (temp != "") jcarea = decimal.Parse(temp);
                  temp = context.Request.Form["generation"];
                  if (temp != "") generation = int.Parse(temp);
                  temp = context.Request.Form["dctime"];
                  if (temp != "") dctime = DateTime.Parse(temp);
                  temp = context.Request.Form["dckdgarea"];
                  if (temp != "") dckdgarea = decimal.Parse(temp);
                  temp = context.Request.Form["fbarea"];
                  if (temp != "") fbarea = decimal.Parse(temp);
                  temp = context.Request.Form["sdlj"];
                  if (temp != "") sdlj = decimal.Parse(temp);
                  temp = context.Request.Form["ljzd"];
                  if (temp != "") ljzd = decimal.Parse(temp);
                  temp = context.Request.Form["ljzzd"];
                  if (temp != "") ljzzd = decimal.Parse(temp);
                  temp = context.Request.Form["fssum"];
                  if (temp != "") fssum = decimal.Parse(temp);
                  temp = context.Request.Form["fsqd"];
                  if (temp != "") fsqd = decimal.Parse(temp);
                  temp = context.Request.Form["fszd"];
                  if (temp != "") fszd = decimal.Parse(temp);
                  temp = context.Request.Form["fszzd"];
                  if (temp != "") fszzd = decimal.Parse(temp);
                  temp = context.Request.Form["tbcnew"];
                  if (temp != "") tbcnew = decimal.Parse(temp);
                  temp = context.Request.Form["yjzh"];
                  if (temp != "") yjzh = decimal.Parse(temp);
                  temp = context.Request.Form["fsrate"];
                  if (temp != "") fsrate = decimal.Parse(temp);
                  temp = context.Request.Form["fztime"];
                  if (temp != "") fztime = DateTime.Parse(temp);
                  temp = context.Request.Form["workarea"];
                  if (temp != "") workarea = decimal.Parse(temp);
                  temp = context.Request.Form["wghwork"];
                  if (temp != "") wghwork = decimal.Parse(temp);
                  temp = context.Request.Form["zja"];
                  if (temp != "") zja = decimal.Parse(temp);
                  temp = context.Request.Form["xja"];
                  if (temp != "") xja = decimal.Parse(temp);
                  temp = context.Request.Form["bda"];
                  if (temp != "") bda = decimal.Parse(temp);
                  temp = context.Request.Form["fla"];
                  if (temp != "") fla = decimal.Parse(temp);
                  temp = context.Request.Form["qttda"];
                  if (temp != "") qttda = decimal.Parse(temp);
                  temp = context.Request.Form["zwyyja"];
                  if (temp != "") zwyyja = decimal.Parse(temp);
                  temp = context.Request.Form["qtsfa"];
                  if (temp != "") qtsfa = decimal.Parse(temp);
                  temp = context.Request.Form["fsfza"];
                  if (temp != "") fsfza = decimal.Parse(temp);
                  temp = context.Request.Form["wghhfa"];
                  if (temp != "") wghhfa = decimal.Parse(temp);
                  temp = context.Request.Form["wlfza"];
                  if (temp != "") wlfza = decimal.Parse(temp);
                  temp = context.Request.Form["rgfza"];
                  if (temp != "") rgfza = decimal.Parse(temp);
                  temp = context.Request.Form["qtfza"];
                  if (temp != "") qtfza = decimal.Parse(temp);
                  temp = context.Request.Form["qtwgha"];
                  if (temp != "") qtwgha = decimal.Parse(temp);
                  temp = context.Request.Form["hxfza"];
                  if (temp != "") hxfza = decimal.Parse(temp);
                  temp = context.Request.Form["fzsum"];
                  if (temp != "") fzsum = decimal.Parse(temp);
                  temp = context.Request.Form["yfarea"];
                  if (temp != "") yfarea = decimal.Parse(temp);
                  temp = context.Request.Form["ffarea"];
                  if (temp != "") ffarea = decimal.Parse(temp);
                  temp = context.Request.Form["zjb"];
                  if (temp != "") zjb = decimal.Parse(temp);
                  temp = context.Request.Form["xjb"];
                  if (temp != "") xjb = decimal.Parse(temp);
                  temp = context.Request.Form["bdb"];
                  if (temp != "") bdb = decimal.Parse(temp);
                  temp = context.Request.Form["flb"];
                  if (temp != "") flb = decimal.Parse(temp);
                  temp = context.Request.Form["qttdb"];
                  if (temp != "") qttdb = decimal.Parse(temp);
                  temp = context.Request.Form["qtsfb"];
                  if (temp != "") qtsfb = decimal.Parse(temp);
                  temp = context.Request.Form["fsb"];
                  if (temp != "") fsb = decimal.Parse(temp);
                  temp = context.Request.Form["rgb"];
                  if (temp != "") rgb = decimal.Parse(temp);
                  temp = context.Request.Form["qtfzb"];
                  if (temp != "") qtfzb = decimal.Parse(temp);
                  temp = context.Request.Form["hfb"];
                  if (temp != "") hfb = decimal.Parse(temp);
                  temp = context.Request.Form["tbcxfz"];
                  if (temp != "") tbcxfz = decimal.Parse(temp);
                  temp = context.Request.Form["wghfzrate"];
                  if (temp != "") wghfzrate = decimal.Parse(temp);
                  temp = context.Request.Form["fzrate"];
                  if (temp != "") fzrate = decimal.Parse(temp);
                  temp = context.Request.Form["czarea"];
                  if (temp != "") czarea = decimal.Parse(temp);
                  temp = context.Request.Form["whzharea"];
                  if (temp != "") whzharea = decimal.Parse(temp);
                  temp = context.Request.Form["czrate"];
                  if (temp != "") czrate = decimal.Parse(temp);
                  temp = context.Request.Form["whzharea"];
                  if (temp != "") whzharea = decimal.Parse(temp);
                  temp = context.Request.Form["czrate"];
                  if (temp != "") whzharea = decimal.Parse(temp);
                  temp = context.Request.Form["fzfy"];
                  if (temp != "") fzfy = decimal.Parse(temp);
                  temp = context.Request.Form["sszs"];
                  if (temp != "") sszs = int.Parse(temp);
                  temp = context.Request.Form["zjl"];
                  if (temp != "") zjl = decimal.Parse(temp);

                  temp = context.Request.Form["xjl"];
                  if (temp != "") xjl = decimal.Parse(temp);
                  temp = context.Request.Form["bdl"];
                  if (temp != "") bdl = decimal.Parse(temp);
                  temp = context.Request.Form["tdkc"];
                  if (temp != "") tdkc = decimal.Parse(temp);
                  temp = context.Request.Form["fsyl"];
                  if (temp != "") fsyl = decimal.Parse(temp);
                  temp = context.Request.Form["yjll"];
                  if (temp != "") yjll = decimal.Parse(temp);
                  temp = context.Request.Form["jzll"];
                  if (temp != "") jzll = decimal.Parse(temp);
                  temp = context.Request.Form["yjl"];
                  if (temp != "") yjl = decimal.Parse(temp);
                  temp = context.Request.Form["hxqt"];
                  if (temp != "") hxqt = decimal.Parse(temp);                 
                  
                  jnxc.Model.addprevention model = new jnxc.Model.addprevention();
                  model.aid = aid;
                  model.dpid = dpid;
                  model.trees = trees;
                  model.shouldarea = shouldarea;
                  model.jzarea = jzarea;
                  model.jcarea = jcarea;
                  model.generation = generation;
                  model.dctime = dctime;
                  model.dckdgarea = dckdgarea;
                  model.fbarea = fbarea;
                  model.sdlj = sdlj;
                  model.ljqd = ljqd;
                  model.ljzd = ljzd;
                  model.ljzzd = ljzzd;
                  model.fssum = fssum;
                  model.fsqd = fsqd;
                  model.fszd = fszd;
                  model.fszzd = fszzd;
                  model.tbcnew = tbcnew;
                  model.yjzh = yjzh;
                  model.fsrate = fsrate;
                  model.fztime = fztime;
                  model.workarea = workarea;
                  model.wghwork = wghwork;
                  model.zja = zja;
                  model.xja = xja;
                  model.bda = bda;
                  model.fla = fla;
                  model.qttda = qttda;
                  model.zwyyja = zwyyja;
                  model.qtsfa = qtsfa;
                  model.fsfza = fsfza;
                  model.wghhfa = wghhfa;
                  model.wlfza = wlfza;
                  model.rgfza = rgfza;
                  model.qtfza = qtfza;
                  model.qtwgha = qtwgha;
                  model.hxfza = hxfza;
                  model.fzsum = fzsum;
                  model.yfarea = yfarea;
                  model.ffarea = ffarea;
                  model.zjb = zjb;
                  model.xjb = xjb;
                  model.bdb = bdb;
                  model.flb = flb;
                  model.qttdb = qttdb;
                  model.qtsfb = qtsfb;
                  model.rgb = rgb;
                  model.qtfzb = qtfzb;
                  model.hfb = hfb;
                  model.tbcxfz = tbcxfz;
                  model.wghfzrate = wghfzrate;
                  model.fzrate = fzrate;
                  model.czarea = czarea;
                  model.whzharea = whzharea;
                  model.czrate = czrate;
                  model.fzfy = fzfy;
                  model.sszs = sszs;
                  model.zjl = zjl;
                  model.xjl = xjl;
                  model.bdl = bdl;
                  model.tdkc = tdkc;
                  model.fsyl = fsyl;
                  model.yjll = yjll;
                  model.jzll = jzll;
                  model.yjl = yjl;
                  model.hxqt = hxqt;
                  model.fsb = fsb;
                model.uid = Web.Admin.myinfo.getID(context);                
                int rid = bll.Add(model);
                if (rid > 0)
                {                    
                    context.Response.Write("T");//返回给前台页面  
                    context.Response.End();
                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();
                }
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();
            }

        }
      
        public void Query(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            {
                int uid = Web.Admin.myinfo.getID(context);
                string uname, utruename, st;
                uname = utruename = st = "";
                //获取前台传来的值 
                if (null != context.Request.Form["search_type"])
                {//获取前台传来的值  
                    st = context.Request.Form["search_type"].ToString().Trim();
                }
                if (null != context.Request.Form["search_value"])
                {//获取前台传来的值  
                    uname = context.Request.Form["search_value"].ToString().Trim();
                }
                if (st == "username")
                {
                    utruename = uname;
                    uname = "";
                }
                int pageRows, page;
                pageRows = 10;
                page = 1;
                string order, sort, oderby; order = sort = oderby = "";
                if (null != context.Request.Form["rows"])
                {
                    pageRows = int.Parse(context.Request.Form["rows"].ToString().Trim());

                }
                if (null != context.Request.Form["page"])
                {

                    page = int.Parse(context.Request.Form["page"].ToString().Trim());

                }
                if (null != context.Request.Form["sort"])
                {

                    order = context.Request.Form["sort"].ToString().Trim();

                }
                if (null != context.Request.Form["order"])
                {

                    sort = context.Request.Form["order"].ToString().Trim();

                }
                StringBuilder strWhere = new StringBuilder();
                if (uname != "")
                {
                    strWhere.AppendFormat(" uname like '%{0}%' and ", uname);
                }
                if (utruename != "")
                {
                    strWhere.AppendFormat(" utruename like '%{0}%' and ", utruename);
                }

                strWhere.AppendFormat(" uid={0} and ", uid);
                int startindex = strWhere.ToString().LastIndexOf("and");//获取最后一个and的位置  
                if (startindex >= 0)
                {
                    strWhere.Remove(startindex, 3);//删除多余的and关键字  
                }
                if (sort != "" && order != "")
                {
                    //strWhere.AppendFormat(" order by {0} {1}", sort, order);//添加排序  
                    oderby = order + " " + sort;
                }
                //DataSet ds = Bnotice.GetList(strWhere.ToString());  //调用不分页的getlist  

                //调用分页的GetList方法  
                DataSet ds = bll.GetListByPage(strWhere.ToString(), oderby, (page - 1) * pageRows + 1, page * pageRows);
                int count = bll.GetRecordCount(strWhere.ToString());//获取条数  
                string strJson = ToJson.Dataset2Json(ds, count);//DataSet数据转化为Json数据  
                context.Response.Write(strJson);//返回给前台页面  
                context.Response.End();
            }

        }
      
        public void Querymy(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int uid = Web.Admin.myinfo.getID(context);
            if (uid != 0)
            {   
                string StartTime = "", EndTime = "",otype="0";
                string idstr = "";
                string areaid = "";
                int id = 0;
                if (null != context.Request.Form["StartTime"])
                {//获取前台传来的值  
                    StartTime = context.Request.Form["StartTime"].ToString().Trim();
                }
                if (null != context.Request.Form["EndTime"])
                {//获取前台传来的值  
                    EndTime = context.Request.Form["EndTime"].ToString().Trim();
                }
                if (null != context.Request.Form["otype"])
                {//获取前台传来的值  
                    otype = context.Request.Form["otype"].ToString().Trim();
                }
                BLL.areainfo blla = new BLL.areainfo();
                DataSet ds1 = blla.GetList("");
                if (otype == "1")
                {
                    if (null != context.Request.Form["idstr"])
                        id = int.Parse(context.Request.Form["idstr"]);
                }
                if (otype == "2")
                {
                    if (null != context.Request.Form["idstr"])
                    {
                        idstr = context.Request.Form["idstr"].ToString().Trim();
                        if (idstr != "")
                        {
                            id = int.Parse(idstr);
                            //根据点击ID找下面所有ID
                            result.Remove(0, result.Length);
                            areaid = id + GetIDByTable(ds1.Tables[0], "aid", "pid", id);
                        }
                    }

                }
                else                
                {
                    string[] pcc = Web.Admin.myinfo.getPCC(context).Split(',');
                    int level = Web.Admin.myinfo.getLevel(context);
                    int aid = blla.GetAid(level, pcc);
                    if (aid != 0)
                    {
                        result.Remove(0, result.Length);
                        areaid = aid + GetIDByTable(ds1.Tables[0], "aid", "pid", aid);

                    }
                    else
                        areaid = "";                    

                }
                int pageRows, page;
                pageRows = 10;
                page = 1;
                string order, sort, oderby; order = sort = oderby = "";
                if (null != context.Request.Form["rows"])
                {
                    pageRows = int.Parse(context.Request.Form["rows"].ToString().Trim());
                }
                if (null != context.Request.Form["page"])
                {
                    page = int.Parse(context.Request.Form["page"].ToString().Trim());
                }
                if (null != context.Request.Form["sort"])
                {
                    order = context.Request.Form["sort"].ToString().Trim();
                }
                if (null != context.Request.Form["order"])
                {
                    sort = context.Request.Form["order"].ToString().Trim();
                }
                StringBuilder strWhere = new StringBuilder();
                if (StartTime != "")
                {
                    strWhere.AppendFormat(" dctime>='{0}' and ", StartTime);
                }
                if (EndTime != "")
                {
                    strWhere.AppendFormat(" dctime<='{0}' and ", EndTime);
                }
                if (otype == "1")
                {
                    strWhere.AppendFormat(" dpid='{0}' and ", id);

                }
                if (areaid != "")
                {
                    strWhere.AppendFormat(" aid in ({0}) and ", areaid);
                }                
                
                //删除多余的and  
                int startindex = strWhere.ToString().LastIndexOf("and");//获取最后一个and的位置  
                if (startindex >= 0)
                {
                    strWhere.Remove(startindex, 3);//删除多余的and关键字  
                }
                if (sort != "" && order != "")
                {
                    oderby = order + " " + sort;
                }
                DataSet ds = bll.GetListByPage(strWhere.ToString(), oderby, (page - 1) * pageRows + 1, page * pageRows);
                int count = bll.GetRecordCount(strWhere.ToString());//获取条数  
                string strJson = ToJson.Dataset2Json(ds, count);//DataSet数据转化为Json数据  
                context.Response.Write(strJson);//返回给前台页面  
                context.Response.End();
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();

            }
        }

        public void Queryt(HttpContext context)
        {
            context.Response.ContentType = "text/json";
            context.Response.ContentEncoding = Encoding.UTF8;
            int uid = Web.Admin.myinfo.getID(context);
            if (uid != 0)
            {
                string[] pcc = Web.Admin.myinfo.getPCC(context).Split(',');
                jnxc.BLL.myharmful mybll = new BLL.myharmful();                           
                DataSet ds = mybll.GetListv(string.Format(" province='{0}'  ", pcc[0]));
                string str = GetTreeJsonByTablea(ds.Tables[0], "mhid", "hname", "1");
                str = "{\"id\":-1,\"text\":\"分病虫浏览\",\"children\":" + str + "}";
                BLL.areainfo blla = new BLL.areainfo();
                //ds = blla.GetList("");
               
                int level = Web.Admin.myinfo.getLevel(context);
                int aid = blla.GetAid(level, pcc);
                string myp="";
                if (level > 3)myp="全国";
            else if (level == 3) myp=pcc[0] ;
            else if (level == 2)myp=pcc[1];
            else if (level == 1) myp= pcc[2];
                ds = blla.GetList("LEN(abh)<>9");
                //ds = blla.GetList("");
                result.Remove(0, result.Length);   
                string strb = GetTreeJsonByTable(ds.Tables[0], "aid", "aname", "pid", aid);
                //string strb = GetTreeJsonByTable(ds.Tables[0], "aid", "aname", "2");
                strb = "{\"id\":-2,\"text\":\"分地区浏览\",\"children\":[{\"id\":"+aid+",\"text\":\""+myp+"\",\"children\":"+ strb + "}]}";
                string strJson = "[{\"id\":0,\"text\":\"全部\",\"children\":[" + str+","+ strb+ "]}]";
                context.Response.Write(strJson);//返回给前台页面  
                context.Response.End();
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();

            }
        }
        private string GetTreeJsonByTablea(DataTable tabel, string idCol, string txtCol, string addattr)
        {
            result.Remove(0, result.Length);           
            if (tabel.Rows.Count > 0)
            {
                result.Append("[");               
                
                    foreach (DataRow row in tabel.Rows)
                    {
                        result.Append("{\"id\":\"" + row[idCol] + "\",\"text\":\"" + row[txtCol].ToString().Trim() + "\",\"type\":\""+addattr+"\"},");                        
                    }
                    result = result.Remove(result.Length - 1, 1);

                    result.Append("]");  
                
            }
            return result.ToString();
        }
        private string GetIDByTable(DataTable tabel,string idCol,string rela, object pId)
        {
            result.Append(sb.ToString());
            sb.Remove(0, sb.Length);
            if (tabel.Rows.Count > 0)
            {                
                string filer = string.Format("{0}='{1}'", rela, pId);
                DataRow[] rows = tabel.Select(filer);
                if (rows.Length > 0)
                {
                    foreach (DataRow row in rows)
                    {
                        sb.Append("," + row[idCol]);
                        if (tabel.Select(string.Format("{0}='{1}'", rela, row[idCol])).Length > 0)
                        {                            
                            GetIDByTable(tabel, idCol,rela, row[idCol]);
                            result.Append(sb.ToString());
                            sb.Remove(0, sb.Length);
                        }
                        result.Append(sb.ToString());
                        sb.Remove(0, sb.Length);
                    }                   
                }                
                result.Append(sb.ToString());
                sb.Remove(0, sb.Length);
            }
            return result.ToString();
        }
        private string GetTreeJsonByTable(DataTable tabel, string idCol, string txtCol, string rela, object pId)
        {
            result.Append(sb.ToString());
            sb.Remove(0, sb.Length);
            if (tabel.Rows.Count > 0)
            {
                sb.Append("[");
                string filer = string.Format("{0}='{1}'", rela, pId);
                DataRow[] rows = tabel.Select(filer);
                if (rows.Length > 0)
                {
                    foreach (DataRow row in rows)
                    {
                        if (row[idCol].ToString() == "140")
                        {
                            string a = "";
                        }
                        sb.Append("{\"id\":\"" + row[idCol] + "\",\"text\":\"" + row[txtCol] + "\",\"type\":\"2\",\"bm\":\"" + row["abh"] + "\"");
                        if (tabel.Select(string.Format("{0}='{1}'", rela, row[idCol])).Length > 0)
                        {
                            //点击展开
                            sb.Append(",\"children\":");
                            GetTreeJsonByTable(tabel, idCol, txtCol, rela, row[idCol]);
                            result.Append(sb.ToString());
                            sb.Remove(0, sb.Length);
                        }
                        result.Append(sb.ToString());
                        sb.Remove(0, sb.Length); ;
                        sb.Append("},");
                    }
                    sb = sb.Remove(sb.Length - 1, 1);
                }
                sb.Append("]");
                result.Append(sb.ToString());
                sb.Remove(0, sb.Length);
            }
            return result.ToString();
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}